import { Vector2 } from "../vector";  
import { CameraEffect } from "./camera-effect";  
import { Engine } from "../engine";

/**
 * 相机震动效果类，继承自CameraEffect
 * 
 * @param engine 游戏引擎实例
 * @param intensity 震动强度，默认值为5
 * @param frequency 震动频率，默认值为20
 * 
 * @method apply 应用震动效果到基础位置
 * @param basePos 基础位置向量
 * @returns 应用震动后的新位置向量
 * 
 * @description
 * 该类实现了相机震动效果，通过正弦和余弦函数计算偏移量，
 * 震动强度会随着效果进度逐渐减弱(fade out效果)
 */
export class ShakeEffect extends CameraEffect {
    private intensity: number;  
  private frequency: number;  
  
  constructor(engine: Engine, intensity: number = 5, frequency: number = 20) {  
    super(engine);  
    this.intensity = intensity;  
    this.frequency = frequency;  
  }  
  
  apply(basePos: Vector2): Vector2 {  
    if (!this.isActive) return basePos;  
  
    const fadeOut = 1 - this.progress;  
    const currentIntensity = this.intensity * fadeOut;  
      
    const offsetX = Math.sin(this.engine.time_ * this.frequency / 1000) * currentIntensity;  
    const offsetY = Math.cos(this.engine.time_ * this.frequency / 1000) * currentIntensity;  
  
    return new Vector2(basePos.x + offsetX, basePos.y + offsetY);  
  }  
}